package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsCouponProductCategoryRelationMapper;
import com.mall.model.domain.SmsCouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_coupon_product_category_relation(优惠券和产品分类关系表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsCouponProductCategoryRelationApiImpl extends ServiceImpl<SmsCouponProductCategoryRelationMapper, SmsCouponProductCategoryRelation>
        implements SmsCouponProductCategoryRelationApi {

    @Autowired
    private SmsCouponProductCategoryRelationMapper smsCouponProductCategoryRelationMapper;

    @Override
    public void deleteByCouponId(Integer id) {

        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductCategoryRelation::getCouponId, id);
        smsCouponProductCategoryRelationMapper.delete(lqw);
    }

    @Override
    public void updateCategoryRelation(Integer id, SmsCouponProductCategoryRelation categoryRelation) {

        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductCategoryRelation::getCouponId, id);
        smsCouponProductCategoryRelationMapper.update(categoryRelation, lqw);
    }

    @Override
    public List<SmsCouponProductCategoryRelation> findByCouponId(Integer id) {

        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsCouponProductCategoryRelation::getCouponId, id);
        return smsCouponProductCategoryRelationMapper.selectList(lqw);
    }

}




